package com.my.json.sensitive.config.handle;

import com.my.json.sensitive.config.AbstractSensitiveHandler;
import com.my.json.sensitive.enums.SensitiveType;
import org.apache.commons.lang3.StringUtils;

/**
 * 固定电话脱敏
 *
 * @author hexinglin
 * @created 2021-12-29 15:35
 **/
public class FixedPhoneSensitiveHandler  extends AbstractSensitiveHandler {
    public FixedPhoneSensitiveHandler() {
    }

    @Override
    public SensitiveType strategy() {
        return SensitiveType.FIXED_PHONE;
    }
    @Override
    public String sensitive(String text) {
        if (StringUtils.isBlank(text)) {
            return "";
        } else {
            int length = StringUtils.length(text);
            if (length <= 4) {
                return text;
            } else {
                String last = StringUtils.right(text, 4);
                return StringUtils.leftPad(last, length, '*');
            }
        }
    }
}

